package com.hsjk.szwj.module.official.controller.app.app;

import com.hsjk.szwj.framework.common.pojo.CommonResult;
import com.hsjk.szwj.framework.security.core.annotations.PreAuthenticated;
import com.hsjk.szwj.module.official.controller.app.app.vo.AppBindOfficialWebsiteAppRespVO;
import com.hsjk.szwj.module.official.controller.app.app.vo.AppOfficialWebsiteAppListRespVO;
import com.hsjk.szwj.module.official.conver.app.OfficialWebsiteAppConvert;
import com.hsjk.szwj.module.official.dal.dataobject.app.OfficialWebsiteAppDO;
import com.hsjk.szwj.module.official.service.app.IOfficialWebsiteAppService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

import static com.hsjk.szwj.framework.common.pojo.CommonResult.success;

/**
 * @author chenjiawei
 * @desc
 * @Date 2023/08/01 09:08
 **/
@Tag(name = "官网应用端 - 应用相关接口")
@RestController
@RequestMapping("/official-website/app")
@Validated
public class AppOfficialWebsiteAppController {

    @Resource
    private IOfficialWebsiteAppService officialWebsiteAppService;

    @PostMapping("/list-bind-app")
    @Operation(summary = "获取绑定的官网app应用列表")
    @PreAuthenticated
    public CommonResult<List<AppBindOfficialWebsiteAppRespVO>> listBindOfficialWebSiteApp() {
        return success(officialWebsiteAppService.listBindOfficialWebSiteApp());
    }

    @GetMapping("/get-list-by-app-category-id")
    @Operation(summary = "根据应用分类id获取应用列表信息")
    @PreAuthenticated
    public CommonResult<List<AppOfficialWebsiteAppListRespVO>> getAppListByAppCategoryId(Integer appCategoryId) {
        List<OfficialWebsiteAppDO> list = officialWebsiteAppService.getAppListByAppCategoryId(appCategoryId);
        return success(OfficialWebsiteAppConvert.INSTANCE.convertAppOfficialWebsiteAppListRespVO(list));
    }
}
